package Base;

import other.DButton;

import javax.swing.*;
import java.awt.*;

public class TextField extends JPanel {

    public String data = "";
    public final Font font = new Font("宋体 ", Font.BOLD, 36);
    public  String name;
    public DButton clearButton = new DButton(new ImageIcon("src/main/resources/icon/login/clear.png"));

    public void init(String nameStr) {
        name=nameStr;
        setSize(500, 64);
        setBackground(Color.white);
        setLayout(null);
        setBorder(null);

        // clear按钮
        clearButton.setBounds(getWidth() - 64 - 5, 0, 64, 64);
        clearButton.setBackground(Color.white);
        clearButton.setVisible(false);
        clearButton.setBorder(null);
        add(clearButton);
    }

    public void setSize(int width, int height) {
        super.setSize(width, height);
        clearButton.setBounds(getWidth() - 64 - 5, 0, 64, 64);
    }

    public void setBounds(int x, int y, int width, int height) {
        super.setBounds(x, y, width, height);
        clearButton.setBounds(getWidth() - 64 - 5, 0, 64, 64);
    }

    // 绘制圆角区域
    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        // 高精度绘图
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(getBackground());
        g2d.fillRoundRect(0, 0, getSize().width, getSize().height, 15, 15); // 设置圆角
    }

}
